use std::error::Error;
use log::info;
use rpc::dto::{RpcData, RpcHeader};
use rpc::{decode, decode_rpc_header, encode, encode_rpc_data, RpcContext};
use rpc::error::{CustomerErrorKind, RpcError};
use rpc::error::RpcError::CustomerError;

#[test]
fn error_test() {
    let error = CustomerError {error_kid: CustomerErrorKind::ErrorPath, message: "error".to_string()};
    info!("{:?}", error.to_string());
    info!("{:?}", error.description());
}

#[test]
fn error_test2() {
    let error = CustomerError {error_kid: CustomerErrorKind::ErrorPath, message: "error".to_string()};
    let header = RpcHeader::new("/demo", "dddd".to_string(), -10);
    let rpc_data = RpcData::build(header, error);

    let context = RpcContext::test_context_with_codec_type("json");
    let data = encode_rpc_data(&context, &rpc_data);
    let data_bytes = data.unwrap();
    println!("{:?}", String::from_utf8(data_bytes.clone()));

    let (header2, d_bytes) = decode_rpc_header(&context, &data_bytes[4..].to_vec()).unwrap();
    let r_d = decode::<RpcError>(&context, d_bytes);
    println!("{:?}", r_d.unwrap());

}